<template>
  <div class="app-container">
    <div class="filter-container">
         <el-form ref="dataForm" :model="temp" label-position="right" label-width="120px" >
       
       
        <el-form-item label="小程序名称" prop="siteName" name="siteName" >
          <el-input v-model="temp.siteName"  />
        </el-form-item>
         <el-form-item label="首页搜索状态" prop="searchStatus" name="searchStatus">
            <el-radio v-model="temp.searchStatus" label="1" size="large">显示</el-radio>
            <el-radio v-model="temp.searchStatus" label="2" size="large">隐藏</el-radio>
        </el-form-item>
         <el-form-item label="新项目提醒" prop="remindPhone"  name="remindPhone">
                    <el-input
                v-model="temp.remindPhone"
                placeholder="新项目提醒手机号"
              />
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
       
        <el-button type="primary" @click="createData()">
          提交
        </el-button>
      </div>
        </div>
        </div>
</template>



<script>
import { GQL } from '@/api/article'
export default {

  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
        temp:{
           siteName:'',
           searchStatus:'',
           remindPhone:''

        },
 

    }
  },
  created() {
     this.getList()
     
  },
  methods: {
 
    getList() {
        const query = {
               "operationName": "allSlSystemConfigs",
                "query":"query allSlSystemConfigs($filter: SlSystemConfigFilter) { allSlSystemConfigs(filter: $filter) { nodes { id remindPhone siteName wpaySearet wpayShopId searchStatus menuName } } }",
                "variables":{ "filter": { "menuName":  { "equalTo": "site_name" } } }
        }
      
       GQL(query).then(response => {
        this.temp = response.data.allSlSystemConfigs.nodes[0]
        // console.log('11111-',this.temp)
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
      
    },
    createData(){
        this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const tempData = Object.assign({}, this.temp)
          let query = {
            "operationName": "updateSlSystemConfigById",
            "query": "mutation updateSlSystemConfigById($input: UpdateSlSystemConfigByIdInput!) { updateSlSystemConfigById(input: $input) { slSystemConfig { wpaySearet wpayShopId siteName searchStatus id } } }",
            "variables": {input: {id: tempData.id, slSystemConfigPatch:tempData}}
          }
          GQL(query).then((res) => {
               if(res.errors){
                  this.$notify({
                    title: '保存失败',
                    message: '保存设置失败',
                    type: 'error',
                    duration: 2000
                  })
              }else{
                  this.$notify({
                    title: '保存成功',
                    message: '保存设置成功',
                    type: 'success',
                    duration: 2000
                  })
              }
       
          })
        }
      })
    },

  }
}
</script>
<style scoped>
</style>
